package cn.co.Servlet;

import cn.co.entry.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "indexServlet",urlPatterns = "/indexServlet")
public class indexServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        HttpSession session = request.getSession();
        User user= (User) session.getAttribute("user");
        if (user==null){
            out.print(
                    "您还没有登录，请<a href='/javawebshiyan2_war_exploded/login.html'>登录</a>");
        }else {
            out.print("您已登录，欢迎你，" + user.getName() + "！");
            out.print("<a href='/javawebshiyan2_war_exploded/LogoutServlet'>退出</a><br>");
            out.print("<a href='/javawebshiyan2_war_exploded/ListCakeServlet'>商城</a><br>");
            Cookie cookie=new Cookie("JSESSIONID",session.getId());
            cookie.setMaxAge(20);
            cookie.setPath("/javawebshiyan2_war_exploded");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
